﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Text;
using Maticsoft.DBUtility;
using Utils;
using System.Collections.Specialized;
using Maticsoft.Model;

public partial class shopcart_Service : FBasePage
{
    // Fields
    public NameValueCollection _system = new NameValueCollection();
    public Maticsoft.BLL.Card carbll = new Maticsoft.BLL.Card();
    public Card cardmodel = new Card();
    public Maticsoft.BLL.orderdetail detailbll = new Maticsoft.BLL.orderdetail();
    public List<orderdetail> detaillist = new List<orderdetail>();
    public bool falg = false;
    protected decimal fare = 0M;
    private bool isRedirect = false;
    public Maticsoft.BLL.Order orderbll = new Maticsoft.BLL.Order();
    public Maticsoft.BLL.orderdetail orderdebll = new Maticsoft.BLL.orderdetail();
    public orderdetail orderdemodel = new orderdetail();
    public string orderid = "A007";
    public List<Order> orderlist = new List<Order>();
    public Order ordermodel = new Order();
    public string pagenum = "1";
    protected bool payselectexpress = false;
    public string service = "";
    public string strpage;
    public Maticsoft.BLL.System sysbll = new Maticsoft.BLL.System();
    public SystemConfig sysconfig = new SystemConfig();
    public Maticsoft.Model.System sysmodel = new Maticsoft.Model.System();
    public Maticsoft.BLL.Team teambll = new Maticsoft.BLL.Team();
    public Team teamodel = new Team();
    protected decimal totalprice = 0M;
    protected UserInfo user = new UserInfo();
    public Maticsoft.BLL.UserInfo userbll = new Maticsoft.BLL.UserInfo();

    // Methods
    public void ConfirmOrder()
    {
        Order order = new Order();
        UserInfo model = new UserInfo();
        model = this.userbll.GetModel(this.userbll.Getuserid(base.UserName));
        order = this.orderbll.GetModel(Convert.ToInt32(this.hiorderid.Value));
        if (order != null)
        {
            if (model.Money < order.Origin)
            {
                if (base.Request["pd_FrpId"] != null)
                {
                    this.service = "yeepay";
                }
                else if (base.Request["paytype"] != null)
                {
                    this.service = base.Request["paytype"].ToString();
                }
                else
                {
                    this.service = "";
                }
                if (this.service == "")
                {
                    this.SetError("请您选择支付方式");
                }
                else
                {
                    this.orderbll.updatebyservice(this.hiorderid.Value, this.service, this.orderbll.Getorder(order.User_id, order.Team_id, Convert.ToInt32(this.hiorderid.Value)), order.Origin);
                    base.Response.Redirect(string.Concat(new object[] { "pay.aspx?orderid=", order.Id, "&pd_FrpId=", base.Request["pd_FrpId"] }));
                }
            }
            else
            {
                this.service = "credit";
                this.orderbll.updatebyservice(this.hiorderid.Value, this.service, this.orderbll.Getorder(order.User_id, order.Team_id, Convert.ToInt32(this.hiorderid.Value)), order.Origin);
                base.Response.Redirect("pay.aspx?orderid=" + this.hiorderid.Value + "&pd_FrpId=" + base.Request["pd_FrpId"]);
            }
        }
        else
        {
            this.SetError("订单不存在");
        }
    }

    public void GetOrder()
    {
        UserInfo info = new UserInfo();
        this.ordermodel = this.orderbll.GetModel(Convert.ToInt32(this.hiorderid.Value));
    }

    public string GetTeam(string id)
    {
        this.teamodel = this.teambll.GetModel(Convert.ToInt32(id));
        if (this.teamodel != null)
        {
            return this.teamodel.Title;
        }
        return "";
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.sysmodel = this.sysbll.GetModel(1);
        this._system = this.sysconfig.GetSystem();
        if (this._system["payselectexpress"] == "1")
        {
            this.payselectexpress = true;
        }
        if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
        {
            base.Response.Redirect("/account/Login.aspx");
        }
        if (base.Request.Form["btnadd"] == "确认订单，付款")
        {
            if (!(base.IsLogin || !(base.UserName == "")))
            {
                base.Response.Redirect("/account/Login.aspx");
            }
            this.ordermodel = this.orderbll.GetModel(Convert.ToInt32(this.hiorderid.Value));
            this.ConfirmOrder();
        }
        if ((base.Request["orderid"] != null) && Utility.IsNum(base.Request["orderid"].ToString()))
        {
            this.hiorderid.Value = base.Request["orderid"].ToString();
            this.ordermodel = this.orderbll.GetModel(Convert.ToInt32(this.hiorderid.Value));
            this.totalprice = this.ordermodel.Origin;
            this.fare = this.ordermodel.Fare;
        }
    }

}